package com.zhengke.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageParams;
import com.zhengke.common.object.AjaxDone;
import com.zhengke.common.object.Result;
import com.zhengke.dao.OrderMapper;
import com.zhengke.pojo.TvOrder;
import com.zhengke.pojo.TvUserCredit;
import com.zhengke.pojo.TvUserCreditDetail;
import com.zhengke.service.IOrderService;
@Service
public class IOrderServiceImpl implements IOrderService {

	@Autowired
	private OrderMapper orderMapper;

	
	@Override
	public Result updateOrder(Integer orderId, Integer orderState) {
		// TODO Auto-generated method stub
		Map<String, Integer> map = new HashMap<String, Integer>();
		
		map.put("orderId",orderId);
		map.put("orderState",orderState);
		
		int result = orderMapper.updateOrder(map);
		
		Result rs = new Result();
		rs.setCode("0");
		rs.setMsg("success");
		return rs;
	}

	/**
	 * 查询不良信用信息ss
	 * 
	 * @param map
	 * @return
	 */
	@Override
	public Result queryTvUserCredit(String userId, String userName, String userPhone, String userCardNumber,int page, int limit) {

		Map<String, String> map = new HashMap<String, String>();;
		map.put("userId",userId);
		map.put("userName",userName);
		map.put("userPhone",userPhone);
		map.put("userCardNumber",userCardNumber);
		
		PageHelper.startPage(page, limit, true);
		
		List<TvUserCredit> list = orderMapper.findTvUserCredits(map);
		PageInfo<TvUserCredit> pageInfo = new PageInfo<TvUserCredit>();
		Result su = new Result();
		su.setCode("0");
		su.setCount(pageInfo.getTotal());
		su.setData(list);
		return su;
	}
	/**
	 * 查看用户不良信用订单详情
	 * 
	 * @param creditId
	 * @return
	 */
	@Override
	public Result findUserCreditDetails(int creditId,int page, int limit) {
		// TODO Auto-generated method stub
		PageHelper.startPage(page,limit,true);
		List<TvUserCreditDetail> list = orderMapper.findUserCreditDetails(creditId);
		PageInfo<TvUserCreditDetail> pageInfo = new PageInfo<TvUserCreditDetail>();
		Result rs = new Result();
		rs.setCode("0");
		rs.setCount(pageInfo.getTotal());
		rs.setData(list);
		
		return rs;
	}
	/**
	 * 修改不良信用金额上限，信用次数上限
	 * 
	 * @param map
	 */
	@Override
	public void updateUserCredit(Integer creditMoney, Integer creditSum, Integer creditId) {
		// TODO Auto-generated method stub
		Map<String,Integer> map = new HashMap<String, Integer>();
		map.put("creditMoney",creditMoney);
		map.put("creditSum",creditSum);
		map.put("creditId",creditId);
		orderMapper.updateUserCredit(map);
		
	}


}

	


